package com.zs.mp.tansfer;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import com.zs.mp.model.Person;
import com.zs.mp.model.vo.PersonVO;

@Mapper(uses = {WeightMapper.class})
public interface PersonMapper {
	
	PersonMapper INSTANCE = Mappers.getMapper(PersonMapper.class);
	
	@Mappings({
		@Mapping(source = "name1", target = "name2"),
		@Mapping(source = "no1", target = "no2"),
		@Mapping(source = "age1", target = "age2", ignore = true),
		@Mapping(source = "height1", target = "height2", qualifiedByName = "heightConvert"),
		@Mapping(source = "weight1", target = "weight2", qualifiedByName = {"WeightMapper","WeightConvert"}),
		@Mapping(source = "sex1.desc", target = "sex2"),
		@Mapping(source = "address.province", target = "province"),
		@Mapping(source = "salary1", target = "salary2",numberFormat = "##.##")
	})
	PersonVO person4PersonVO(Person person);
	
	@Named("heightConvert")
	default Double heightConvert(Long height) {
		return height * 1.0 / 100;
	}
}
